package com.example.greenshuttle;

import java.util.Calendar;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Vibrator;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

public class Chatyaocan extends Activity {
	private TextView mChoice;
	private CharSequence Cmeal;

	private ShakeListener mShakeListener;
	private Vibrator mVibrator;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.chat_yaocan);
		// ����activityʱ���Զ����������
		getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

		mChoice = (TextView) findViewById(R.id.text_yaocan);

		mVibrator = (Vibrator) getApplication().getSystemService(
				VIBRATOR_SERVICE);

		mShakeListener = new ShakeListener(this);
		Log.i("sdfsdf", "asd");
		mShakeListener.setOnShakeListener(new ShakeListener.OnShakeListener() // new
																				// onShakeListener()
																				// ��Ȼ���ˣ���
				{
					@Override
					public void onShake() {
						Log.i("sdfsdf", "asd");
						// Toast.makeText(getApplicationContext(),
						// "��Ǹ����ʱû���ҵ���ͬһʱ��ҡһҡ���ˡ�\n����һ�ΰɣ�",
						// Toast.LENGTH_SHORT).show();
						mShakeListener.stop();
						mVibrator.vibrate(new long[] { 500, 200, }, -1);
						new Handler().postDelayed(new Runnable() {
							@Override
							public void run() {
								initData();
								mChoice.setText(Cmeal);
								mVibrator.cancel();
								mShakeListener.start();
							}
						}, 2000);
					}
				});

	}

	private void initData() {
		switch (tuijishu(5)) {
		case 0:
			Cmeal = "��~����ȥ��ʳ�ð�~";
			break;
		case 1:
			Cmeal = "ŭ���������ţ����棡";
			break;
		case 2:
			Cmeal = "�þ�û�����з���~";
			break;
		case 3:
			Cmeal = "������Ѫ����������";
			break;
		case 4:
			Cmeal = "����fighting,����ͺ�ˮ��";
			break;
		}

	}

	private int tuijishu(int sum) {
		Calendar c = Calendar.getInstance();
		int sec = c.get(Calendar.SECOND);

		return (int) ((1000 * Math.random() * sec) % sum);
	}

	public void chat_btn_back(View v) {
		mVibrator.cancel();
		this.finish();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (mShakeListener != null) {
			mShakeListener.stop();
		}
	}
}
